package com.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Controller
@Slf4j
public class UserController {


     @RequestMapping({"/success.html"})
    public String success(Map<String,Object> map){
        map.put("hello","<h1>你好</h1>");
        map.put("users", Arrays.asList("小海","双全","许晴"));
        return "success";
    }

    @PostMapping("/user/login")
    public String login(@RequestParam("username")String username, @RequestParam("pwd")String pwd, HttpSession session, Map<String,Object> map){
        //System.out.println(username+"========="+password);
        if(!StringUtils.isEmpty(username)&&"123".equals(pwd)){
            //登录成功
            session.setAttribute("username",username);
            //Model  ModelAndView
            //request
            return "redirect:/main.html";
        }else{
            //登录失败
            map.put("msg","用户名或者密码错误");
            return "login";
        }
    }



}
